import { Component, Injector, ViewEncapsulation } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { finalize } from 'rxjs/operators';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import {
    PipelineListDto,
    PipelineNodesServiceProxy
} from '@shared/service-proxies/service-proxies';

@Component({
    selector: 'act-common',
    templateUrl: './act-common.component.html',
    encapsulation: ViewEncapsulation.None,
    animations: [appModuleAnimation()]
})
export class ActCommonModalComponent extends AppComponentBase {
    saving = false;

    pipe: PipelineListDto = new PipelineListDto();

    remark = '';

    constructor(
        injector: Injector,

        private _nodeService: PipelineNodesServiceProxy
    ) {
        super(injector);
    }

    load(pipe: PipelineListDto): void {
        this.pipe = pipe;

        this._nodeService.getNodeRemark(pipe.id).subscribe(result => {
            this.remark = result;
        });
    }

    save(): void {
        this.saving = true;

        this._nodeService
            .setNodeRemark(this.pipe.id, this.remark)
            .pipe(
                finalize(() => {
                    this.saving = false;
                })
            )
            .subscribe(result => {
                this.notify.success('生成定制单成功');
            });
    }
}
